package com.situ.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebListener;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ajax")
public class AjaxServelt extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("AjaxServelt.doGet()");
		String name = req.getParameter("name");
		System.out.println("name: " + name);
		
		// 通过response告诉浏览器以什么样的编码来解析这个数据
		resp.setContentType("text/html;charset=utf-8");
		// {"name":"李四","age":23}
		resp.getWriter().write("{\"name\":\"李四\",\"age\":23}");
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("AjaxServelt.doPost()");
		
		String name = req.getParameter("name");
		System.out.println("name: " + name);
		
		// 通过response告诉浏览器以什么样的编码来解析这个数据
		resp.setContentType("text/html;charset=utf-8");
		// {"name":"李四","age":23}
		resp.getWriter().write("{\"name\":\"王五\",\"age\":23}");
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
